package com.lagou.edu.controller;


import com.lagou.edu.dao.CodeDao;
import com.lagou.edu.service.CodeService;
import org.aspectj.apache.bcel.classfile.Code;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/code")
public class CodeController {

    @Autowired
    private CodeService codeService;


    @RequestMapping("/create/{email}")
    public String sendCode(@PathVariable("email")String email){

        System.out.println(email);

        if(codeService.createAndSendCode(email)){
            return "success";
        }
        return "error";
    }

    @RequestMapping("/validate/{email}/{code}")
    public String validate(@PathVariable("email")String email, @PathVariable("code") String code){

        System.out.println(email);
        System.out.println(code);

        if(codeService.validateCode(email,code)){
            return "success";
        }
        return "error";
    }

}
